#ifndef _GAMEBOARD_H_
#define _GAMEBOARD_H_

#include "Cell.h"       //For the Color enum.
#include <utility>
#include <windows.h>   // WinApi header
using std::pair;

const int NUM_COLORS = 6;	//The number of colors available. Red, Green, Blue, Yellow, Violet, Pink
const int SMALL = 12;	//The size of the small board
const int MEDIUM = 17;	//The size of the medium board
const int LARGE = 22;	//The size of the large board

const int USER_PLAYED = 1;	//This is if the user elects to make their own moves
const int COMP_PLAY_BY_PLAY = 2;	//If they want to watch the computer go play-by-play
const int STAT_DRIVER = 3;	//Or if they want to run the game x amount of times and see the results. wins, total runs, %won.

class GameBoard
{
private:
        Color _ColorOfNextFlood; //The color the computer chooses for the next flood
        Cell ** _masterptr;  //The pointer to the game board. This pointer points to the master block in the upper left corner.
 		HANDLE  hConsole;	//For displaying colors on the console
		pair <int, Color> colorPriority;	//This is for keeping track of which color needs to be flooded next via the countColorNextToFlooded function.
                                                
		int colorPriorityCompare;	//This tallies up the colors for the next turn, and the color with the highest tally becomes the next turn.
		int displayColor;	//For displaying the right color in the console

		int SIZE;	//This is the size of the board the user specified
		int numR, numG, numB, numY, numV, numP;	//The number of each cell on the gameboard
		int numberOfTries;	//Small board = 22 tries, medium = 30 tries, large = 36 tries
		int currentTry;	//This keeps track of the current try the user/computer is on
		int gameType;	//This is to determine either user played board, computer play by play, or statistical driver
		char userColorChoice;	//For the user input on what they want the next color to be if they choose to play themselves


public:
        GameBoard(int size, int gameType);	//The constructor will define and populate gameboard with user specified
											//size and random colors. 12x12, 17x17, and 22x22 are the size options.
		~GameBoard();	//The default destructor, deletes _masterptr and associated pointers

		void DisplayBoard(int size);		//Will use the _masterptr to display/update board

		//Solver functions
		void countColorNextToFlooded(Color);//Counts the number of cells one cell away from the flooded area
		void ColorCycle();					//Cycles through the colors each turn to find the highest priority color
		void AssignNextTo();				//Loops through the board to mark cells next to the flooded area
		void Flooder(Color);				//Changes the color of each flooded cell, and sets each NextTo cell to flooded
		void VeinOfNextTo(int, int);		//Uses recursion to find each cell that is part of a vein touching the flooded area
		int GameDriver();					//The function calling the other functions to drive the game. Returns 1 for a win, 0 for a loss.
		void checkForElimination();			//This function checks to see if a color can be completely eliminated, and also runs the ColorCycle function if none can.

		bool GameEnd();						//Checks the board each turn for a win, returns a bool
		

		//Setter functions
		void setGameType(int type) { gameType = type; }	//This function will initialize the board with a certain user specified game type
		void addToColor(char);				//This function will add 1 to whatever color is created during the gameboard creation
		void minusFromColor(char);			//This function will minus 1 to whatever color has their 'nextTo' bool set to TRUE

		//Getter functions
		void GetCellColor(int, int);		//Returns an int (displayColor), that will tell cout what color to display
		int getPriority();					//Returns the priority of the highest priority color found (an int)
};

#endif _GAMEBOARD_H_
